Nx Remote Cache 七牛云插件 NPM 发包准备
概述
将自研的 Nx Remote Cache 七牛云存储插件发布到 NPM 公共仓库前,需要完成三项准备工作:创建独立 GitHub 仓库、完善 package.json 元数据、编写 README 文档。本节详细说明每个步骤的要点与最佳实践。
创建独立仓库
从 Nx 官方插件(如 nx-remote-cache-oss)的仓库结构获取灵感,创建新的独立仓库:
# 仓库名称约定:nx-remote-cache-qiniu
# Description 参考:Nx remote cache implementation using Qiniu Cloud Storage
bash
仓库命名遵循 nx-remote-cache-<provider> 的社区惯例,便于用户在 NPM 上搜索识别。
配置 package.json
发布前需确保 package.json 包含以下必要字段:
{
"name": "nx-remote-cache-qiniu",
"version": "1.0.0",
"description": "Nx remote cache implementation using Qiniu Cloud Storage",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Your Name <your.email@example.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/username/nx-remote-cache-qiniu.git"
},
"keywords": ["nx", "remote-cache", "qiniu", "monorepo"],
"files": ["dist", "README.md"]
}
json
关键字段说明
| 字段 | 作用 | 注意事项 |
|---|---|---|
name | NPM 包名,全局唯一 | 遵循 nx-remote-cache-* 前缀规范 |
version | 语义化版本号 | 首次发布为 1.0.0 |
author | 作者信息 | 邮箱格式需含尖括号:Name <email> |
repository | 源码地址 | 提供完整的 HTTPS Git URL |
files | 发布文件白名单 | 仅包含编译产物和文档 |
编写 README 文档
参考 nx-remote-cache-oss 官方文档结构,README 应包含以下模块:
# nx-remote-cache-qiniu
## Description
基于七牛云对象存储的 Nx Remote Cache 实现。
## Compatibility
- Nx >= 16.x
- Node >= 18.x
## Setup
\```bash
npm install nx-remote-cache-qiniu --save-dev
\```
## Options
| 参数 | 类型 | 默认值 | 说明 |
|------|------|-------|------|
| accessKey | string | - | 七牛云 Access Key |
| secretKey | string | - | 七牛云 Secret Key |
| bucket | string | - | 存储空间名称 |
| zone | string | 'z0' | 存储区域 |
## Configuration
在 `nx.json` 中配置:
\```json
{
"tasksRunnerOptions": {
"default": {
"runner": "nx-remote-cache-qiniu",
"options": {
"accessKey": "your-access-key",
"secretKey": "your-secret-key",
"bucket": "your-bucket-name"
}
}
}
}
\```
## Advanced Configuration
...自定义选项说明...
markdown
README 编写技巧
- 借助 AI 工具:可将官方文档(如
nx-remote-cache-oss的 README)作为参考,让 AI 工具辅助生成中英文版本 - 结构对齐:保持与 Nx 生态其他 remote cache 插件的文档结构一致
- 配置示例:提供完整的
nx.json配置示例和最小可用配置 - NPM 发布检查:确保 README 在 NPM 包页面渲染正确
发包检查清单
# 1. 确认构建产物存在
ls dist/
# 2. 确认 package.json 完整
npm pack --dry-run
# 3. 登录 NPM
npm login
# 4. 发布
npm publish
bash
参考资源
- Nx Remote Cache 官方文档:https://nx.dev/nx-api/nx/devkit-plugins/documents/nx-plugin
nx-remote-cache-oss:参考仓库结构与 API 设计- NPM 发布指南:https://docs.npmjs.com/cli/v10/commands/npm-publish
↑